<?php

defined('SYSPATH') or die('No direct script access.');

class Controller_Templates extends Controller_Template {

    public $template = 'template';

    /**
     * The before() method is called before your controller action.
     * In our template controller we override this method so that we can
     * set up default values. These variables are then available to our
     * controllers if they need to be modified.
     */
    public function before() {
        parent::before();

        if ($this->auto_render) {
            // Initialize empty values
            $this->template->title = '';
            $this->template->content = '';

            $this->template->css = array();
            $this->template->js = array();
        }
    }

    /**
     * The after() method is called after your controller action.
     * In our template controller we override this method so that we can
     * make any last minute modifications to the template before anything
     * is rendered.
     */
    public function after() {
        if ($this->auto_render) {
            $styles = array(
                'style'
            );

            $scripts = array(
                'plugins',
                'script',
            );
            
            $styles = array_merge($styles, $this->template->css);
            $scripts = array_merge($scripts, $this->template->js);
            
            $this->template->styles = HTML::style($styles);
            $this->template->scripts = HTML::script($scripts);
        }
        parent::after();
    }

}